package com.github.slowrookie.persistence;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
 * 树形结构
 * 
 * @author 刘佳兴
 */
@MappedSuperclass
public abstract class TreePersistable extends AuditablePersistable {

	private static final long serialVersionUID = 1L;
	
	@NotNull
	@Column(length = 40, nullable = true)
	protected String name;
	
	@NotNull
	@Column(unique = true, nullable= false)
	protected String code;
	
	@Column(unique = true, nullable = false)
	protected String hiberarchy;
	
	protected Long parent = 0L;
	
	@JsonInclude(Include.NON_EMPTY)
	@Transient
	private List<TreePersistable> children = new ArrayList<>();
	
	@JsonInclude(Include.NON_EMPTY)
	@Transient
	private Boolean leaf;
	
	
	public TreePersistable() {
		super();
	}
	
	public TreePersistable(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getHiberarchy() {
		return hiberarchy;
	}

	public void setHiberarchy(String hiberarchy) {
		this.hiberarchy = hiberarchy;
	}

	public Long getParent() {
		return parent;
	}

	public void setParent(Long parent) {
		this.parent = parent;
	}

	public List<TreePersistable> getChildren() {
		return children;
	}

	public void setChildren(List<TreePersistable> children) {
		this.children = children;
	}

	public Boolean getLeaf() {
		return leaf;
	}

	public void setLeaf(Boolean leaf) {
		this.leaf = leaf;
	}

}
